/**
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
 *
 * Unit tests are class methods that verify whether a particular piece
 * of code is working properly. Unit test methods take no arguments,
 * commit no data to the database, and are flagged with the testMethod
 * keyword in the method definition.
 *
 * All test methods in an organization are executed whenever Apex code is deployed
 * to a production organization to confirm correctness, ensure code
 * coverage, and prevent regressions. All Apex classes are
 * required to have at least 75% code coverage in order to be deployed
 * to a production organization. In addition, all triggers must have some code coverage.
 * 
 * The @isTest class annotation indicates this class only contains test
 * methods. Classes defined with the @isTest annotation do not count against
 * the organization size limit for all Apex scripts.
 *
 * See the Apex Language Reference for more information about Testing and Code Coverage.
 */
@isTest
private class trg_ChamberHistoryTest {

    static testMethod void myUnitTest() 
    {
        // TO DO: implement unit test
        //For Legal Status...
        Legal_Status__c legalStatus1 = new Legal_Status__c();
        legalStatus1.Active__c = true;
        legalStatus1.Name = 'Free Zone Entity';
        legalStatus1.Short_Name_English__c = 'F.Z.E';
        insert legalStatus1;
        
        Legal_Status__c legalStatus2 = new Legal_Status__c();
        legalStatus2.Active__c = true;
        legalStatus2.Name = 'Free Zone Company';
        legalStatus2.Short_Name_English__c = 'F.Z.C';
        insert legalStatus2;
        
        //Account Object Record...
        Account accountObject = new Account();
        accountObject.Name = 'Test Account';
        //accountObject.LicenseNumber__c = serialObject.id;
        accountObject.License_Application_Step__c = 'Record Created';
        accountObject.License_Application_Type__c = 'New License';
        accountObject.Activity__c = 'Trading - Three Activity';
        accountObject.License_Issue_Date__c = system.today();
        accountObject.License_Expiry_Date__c = System.Today().addYears(1);
        accountObject.Master_Account_Flag__c = true;
        accountObject.LegalStatus__c = legalStatus2.id;
        insert accountObject;
        
        //Sub Activity Object Record...
        Sub_Activity__c subActivityObject = new Sub_Activity__c();
        subActivityObject.Activity_Type__c = 'Commercial';
        subActivityObject.Name = 'Test Activity';
        insert subActivityObject;
        
        //Sub Activity Object Record...
        Sub_Activity__c subActivityObject1 = new Sub_Activity__c();
        subActivityObject1.Activity_Type__c = 'Commercial';
        subActivityObject1.Name = 'Test Activity1';
        insert subActivityObject1;
        
        
        Contact contactObject1 = new Contact();
        contactObject1.LastName = 'Test 2 Shareholder';
        contactObject1.AccountId = accountObject.id;
        contactObject1.Contact_Type__c = 'Shareholder';
        insert contactObject1;
                      
        Contact contactObject2 = new Contact();
        contactObject2.LastName = 'Test 2 Shareholder';
        contactObject2.AccountId = accountObject.id;
        contactObject2.Contact_Type__c = 'Shareholder';
        insert contactObject2;
        
        Share_Ownership__c shareOwnerObject1 = new Share_Ownership__c();
        shareOwnerObject1.Company__c = accountObject.Id;
        shareOwnerObject1.Ownership__c = 50;
        shareOwnerObject1.Share_Profit__c = 50;
        shareOwnerObject1.Shareholder__c = contactObject2.id;
        insert shareOwnerObject1;
        
        Share_Ownership__c shareOwnerObject2 = new Share_Ownership__c();
        shareOwnerObject2.Company__c = accountObject.Id;
        shareOwnerObject2.Ownership__c = 50;
        shareOwnerObject2.Share_Profit__c = 50;
        shareOwnerObject2.Shareholder__c = contactObject2.id;
        insert shareOwnerObject2;
        
        //For Account Activity Object Records FOR EDIT...
        Account_Activity__c accountActivityObject = new Account_Activity__c();
        accountActivityObject.Account__c = accountObject.Id;
        accountActivityObject.Activity__c = subActivityObject.Id; 
        accountActivityObject.Active__c = true;
        insert accountActivityObject;
        
         //For Account Activity Object Records FOR DELETE...
        Account_Activity__c accountActivityObject1 = new Account_Activity__c();
        accountActivityObject1.Account__c = accountObject.Id;
        accountActivityObject1.Activity__c = subActivityObject.Id; 
        accountActivityObject1.Active__c = true;
        insert accountActivityObject1;
        
        
        //For Amendment Record Type...//For Updating the Authorized Manager...
        
        //Map<string,RecordType> amendmentRecordTypeMap = new Map<string,RecordType>([SELECT Id,SObjectType,DeveloperName,IsActive FROM RecordType where SObjectType =: 'Amendment__c' And DeveloperName IN('Company_Amendment_Change_Company_Name','Company_Amendment_Change_License_Type','Shareholder_Amendment_Add_Partner')]);
        Map<string,RecordType> amendmentRecordTypeMap = new Map<string,RecordType>();
        for(RecordType tempObject : [SELECT Id,SObjectType,DeveloperName,IsActive FROM RecordType where SObjectType =: 'Amendment__c' And DeveloperName IN('Company_Amendment_Change_Company_Name','Company_Amendment_Change_License_Type','Shareholder_Amendment_Add_Partner','Company_Amendment_Change_Company_Manager','Company_Amendment_Change_Company_Activity')])
        {
            amendmentRecordTypeMap.put(tempObject.DeveloperName, tempObject);
            
        }
                  
        //For Amendment Object For Company Name...
        Amendment__c amendmentObject = new Amendment__c();
        amendmentObject.RecordTypeId = amendmentRecordTypeMap.get('Company_Amendment_Change_Company_Name').Id;
        amendmentObject.Account__c = accountObject.Id;
        amendmentObject.New_Company_Name__c = 'Test New Name';
        amendmentObject.New_Company_Name_Arabic__c = 'test New Name Arabic';
        //amendmentObject.Chamber_History__c = chamberObject.id;
        insert amendmentObject;
        
        
        //For Chamber History Object...
        Chamber_History__c chamberObject = new Chamber_History__c();
        chamberObject.Company__c = accountObject.Id;
        chamberObject.Chamber_History_Status__c = 'Sent To Chamber';
        chamberObject.Chamber_Issue_Date__c = System.today();
        chamberObject.Chamber_Expiry_Date__c = System.today().addYears(1);
        chamberObject.Sent_to_Chamber_Date__c = System.today();
        chamberObject.Chamber_of_Commerce_Number__c  = '1234213';
        chamberObject.Amendment__c = amendmentObject.Id;
        insert chamberObject;
        
        //Update the Amendment Object...
        amendmentObject.Chamber_History__c = chamberObject.id;
        update amendmentObject;
        
        //Now Update the Chamber History to trigger the Test Class...
        chamberObject.Chamber_History_Status__c = 'Approved by Chamber';
        chamberObject.Received_From_Chamber_Date__c = System.today();
        update chamberObject;
        
        
        //For Amendment Object For Company License Type...
        Amendment__c amendmentObject1 = new Amendment__c();
        amendmentObject1.RecordTypeId = amendmentRecordTypeMap.get('Company_Amendment_Change_License_Type').Id;
        amendmentObject1.Account__c = accountObject.Id;
        amendmentObject1.New_Company_Name__c = 'Test New Name';
        amendmentObject1.New_Company_Name_Arabic__c = 'test New Name Arabic';
        amendmentObject1.Previous_License_Type__c = accountObject.Activity__c;
        amendmentObject1.New_License_Type__c = accountObject.Activity__c;
        
        insert amendmentObject1;
        
        
        //For Chamber History Object...
        Chamber_History__c chamberObject1 = new Chamber_History__c();
        chamberObject1.Company__c = accountObject.Id;
        chamberObject1.Chamber_History_Status__c = 'Sent To Chamber';
        chamberObject1.Chamber_Issue_Date__c = System.today();
        chamberObject1.Chamber_Expiry_Date__c = System.today().addYears(1);
        chamberObject1.Sent_to_Chamber_Date__c = System.today();
        chamberObject1.Chamber_of_Commerce_Number__c = '123213';
        chamberObject1.Amendment__c = amendmentObject1.Id;
        insert chamberObject1;
        
        //Update the Amendment Object...
        amendmentObject1.Chamber_History__c = chamberObject1.id;
        update amendmentObject1;
                
        //For Amendment Activity Object... Add Flag...
        Amendment_Activity__c amendemntActivityObject = new Amendment_Activity__c();
        amendemntActivityObject.Account__c = accountObject.Id;
        amendemntActivityObject.Active__c = true;
        amendemntActivityObject.Activity__c = subActivityObject.id;
        amendemntActivityObject.Add_Flag__c  = true;
        amendemntActivityObject.Amendment__c = amendmentObject1.Id;
        insert amendemntActivityObject; 
        
        //For Edit Flag...        
        Amendment_Activity__c amendemntActivityObject1 = new Amendment_Activity__c();
        amendemntActivityObject1.Account__c = accountObject.Id;
        amendemntActivityObject1.Active__c = true;
        amendemntActivityObject1.Activity__c = subActivityObject1.id;
        amendemntActivityObject1.Account_Activity__c = accountActivityObject.Id;
        amendemntActivityObject1.Edit_Flag__c  = true;
        amendemntActivityObject1.Amendment__c = amendmentObject1.Id;
        insert amendemntActivityObject1;
        
        //For Delete Flag...
        Amendment_Activity__c amendemntActivityObject2 = new Amendment_Activity__c();
        amendemntActivityObject2.Account__c = accountObject.Id;
        amendemntActivityObject2.Active__c = true;
        amendemntActivityObject2.Activity__c = subActivityObject1.id;
        amendemntActivityObject2.Delete_Flag__c  = true;
        amendemntActivityObject2.Account_Activity__c = accountActivityObject1.Id;
        amendemntActivityObject2.Amendment__c = amendmentObject1.Id;
        insert amendemntActivityObject2;
        
        //Now Update the Chamber History to trigger the Test Class...
        chamberObject1.Chamber_History_Status__c = 'Approved by Chamber';
        chamberObject1.Received_From_Chamber_Date__c = System.today();
        update chamberObject1;
        
        
         //For Amendment Object For Share Ownership...
        Amendment__c amendmentObject2 = new Amendment__c();
        amendmentObject2.RecordTypeId = amendmentRecordTypeMap.get('Shareholder_Amendment_Add_Partner').Id;
        amendmentObject2.Account__c = accountObject.Id;
        amendmentObject2.New_Company_Name__c = 'Test New Name';
        amendmentObject2.New_Company_Name_Arabic__c = 'test New Name Arabic';
        insert amendmentObject2;
        
        
        //For Chamber History Object...
        Chamber_History__c chamberObject2 = new Chamber_History__c();
        chamberObject2.Company__c = accountObject.Id;
        chamberObject2.Chamber_History_Status__c = 'Sent To Chamber';
        chamberObject2.Chamber_Issue_Date__c = System.today();
        chamberObject2.Chamber_Expiry_Date__c = System.today().addYears(1);
        chamberObject2.Sent_to_Chamber_Date__c = System.today();
        chamberObject2.Amendment__c = amendmentObject2.Id;
        chamberObject2.Chamber_of_Commerce_Number__c = '123213';
        insert chamberObject2;
        
        
        //Update the Amendment Object...
        amendmentObject2.Chamber_History__c = chamberObject2.id;
        update amendmentObject2;
        
        
        //For ShareHolder Amendment Object Add Flag...
        Shareholder_Amendment__c shareAmendmentObject = new Shareholder_Amendment__c();
        shareAmendmentObject.Account__c = accountObject.id;
        shareAmendmentObject.Amendment__c = amendmentObject2.Id;
        shareAmendmentObject.Add_Flag__c = true; 
        shareAmendmentObject.Ownership__c = 10;
        shareAmendmentObject.Share_Profit__c = 10;
        insert shareAmendmentObject;
        
        //For ShareHolder Amendment Object Edit Flag...
        Shareholder_Amendment__c shareAmendmentObject1 = new Shareholder_Amendment__c();
        shareAmendmentObject1.Account__c = accountObject.id;
        shareAmendmentObject1.Contact__c = contactObject1.id;
        shareAmendmentObject1.Share_Ownership__c = shareOwnerObject1.id;
        shareAmendmentObject1.Amendment__c = amendmentObject2.Id;
        shareAmendmentObject1.Edit_Flag__c = true; 
        shareAmendmentObject1.Ownership__c = 40;
        shareAmendmentObject1.Share_Profit__c = 40;
        insert shareAmendmentObject1;
        
        
        //For ShareHolder Amendment Object Delete Flag...
        Shareholder_Amendment__c shareAmendmentObject2 = new Shareholder_Amendment__c();
        shareAmendmentObject2.Account__c = accountObject.id;
        shareAmendmentObject2.Contact__c = contactObject2.id;
        shareAmendmentObject2.Share_Ownership__c = shareOwnerObject2.id;
        shareAmendmentObject2.Amendment__c = amendmentObject2.Id;
        shareAmendmentObject2.Delete_Flag__c = true; 
        shareAmendmentObject2.Ownership__c = 50;
        shareAmendmentObject2.Share_Profit__c = 50;
        insert shareAmendmentObject2;
        
         //Now Update the Chamber History to trigger the Test Class...
        chamberObject2.Chamber_History_Status__c = 'Approved by Chamber';
        chamberObject2.Received_From_Chamber_Date__c = System.today();
        update chamberObject2;
        
        //For Amendment Object For Company Manager...
        Amendment__c amendmentObject3 = new Amendment__c();
        amendmentObject3.RecordTypeId = amendmentRecordTypeMap.get('Company_Amendment_Change_Company_Manager').Id;
        amendmentObject3.Account__c = accountObject.Id;
        amendmentObject3.New_Authorize_Manager__c = contactObject1.id;
        insert amendmentObject3;
        
        
        //For Chamber History Object...
        Chamber_History__c chamberObject3 = new Chamber_History__c();
        chamberObject3.Company__c = accountObject.Id;
        chamberObject3.Chamber_History_Status__c = 'Sent To Chamber';
        chamberObject3.Chamber_Issue_Date__c = System.today();
        chamberObject3.Chamber_Expiry_Date__c = System.today().addYears(1);
        chamberObject3.Sent_to_Chamber_Date__c = System.today();
        chamberObject3.Chamber_of_Commerce_Number__c = '123213';
        chamberObject3.Amendment__c = amendmentObject3.Id;
        insert chamberObject3;
        
        //Update the Amendment Object...
        amendmentObject3.Chamber_History__c = chamberObject3.id;
        update amendmentObject3;
        
        //Now Update the Chamber History to trigger the Test Class...
        chamberObject3.Chamber_History_Status__c = 'Approved by Chamber';
        chamberObject3.Received_From_Chamber_Date__c = System.today();
        update chamberObject3;
        
        
        //For Amendment Object For Change Company Activity... (EDIT)
        Amendment__c amendmentObject4 = new Amendment__c();
        amendmentObject4.RecordTypeId = amendmentRecordTypeMap.get('Company_Amendment_Change_Company_Activity').Id;
        amendmentObject4.Account__c = accountObject.Id;
        amendmentObject4.Action__c = 'Edit';
        amendmentObject4.Current_Activity_1__c = subActivityObject.id;
        amendmentObject4.New_Activity_1__c = subActivityObject.id;//Current_Activity_1__c
        amendmentObject4.Current_Activity_2__c = subActivityObject1.id;
        amendmentObject4.New_Activity_2__c = subActivityObject1.id;
        amendmentObject4.Current_Activity_3__c = subActivityObject1.id;
        amendmentObject4.New_Activity_3__c = subActivityObject1.id;
        insert amendmentObject4;
        
        
        //For Chamber History Object...
        Chamber_History__c chamberObject4 = new Chamber_History__c();
        chamberObject4.Company__c = accountObject.Id;
        chamberObject4.Chamber_History_Status__c = 'Sent To Chamber';
        chamberObject4.Chamber_Issue_Date__c = System.today();
        chamberObject4.Chamber_Expiry_Date__c = System.today().addYears(1);
        chamberObject4.Sent_to_Chamber_Date__c = System.today();
        chamberObject4.Amendment__c = amendmentObject4.Id;
        chamberObject4.Chamber_of_Commerce_Number__c = '123213';
        insert chamberObject4;
        
        //Update the Amendment Object...
        amendmentObject4.Chamber_History__c = chamberObject4.id;
        update amendmentObject4;
        
        //Now Update the Chamber History to trigger the Test Class...
        chamberObject4.Chamber_History_Status__c = 'Approved by Chamber';
        chamberObject4.Received_From_Chamber_Date__c = System.today();
        update chamberObject4;        
        
        
        //For Amendment Object For Change Company Activity... (DELETE)
        Amendment__c amendmentObject5 = new Amendment__c();
        amendmentObject5.RecordTypeId = amendmentRecordTypeMap.get('Company_Amendment_Change_Company_Activity').Id;
        amendmentObject5.Account__c = accountObject.Id;
        amendmentObject5.Action__c = 'Delete';
        amendmentObject5.Current_Activity_1__c = subActivityObject.id;
        amendmentObject5.New_Activity_1__c = subActivityObject.id;//Current_Activity_1__c
        amendmentObject5.Current_Activity_2__c = subActivityObject1.id;
        amendmentObject5.New_Activity_2__c = subActivityObject1.id;
        amendmentObject5.Current_Activity_3__c = subActivityObject1.id;
        amendmentObject5.New_Activity_3__c = subActivityObject1.id;
        insert amendmentObject5;
        
        
        //For Chamber History Object...
        Chamber_History__c chamberObject5 = new Chamber_History__c();
        chamberObject5.Company__c = accountObject.Id;
        chamberObject5.Chamber_History_Status__c = 'Sent To Chamber';
        chamberObject5.Chamber_Issue_Date__c = System.today();
        chamberObject5.Chamber_Expiry_Date__c = System.today().addYears(1);
        chamberObject5.Sent_to_Chamber_Date__c = System.today();
        chamberObject5.Amendment__c = amendmentObject5.Id;
        chamberObject5.Chamber_of_Commerce_Number__c = '123213';
        insert chamberObject5;
        
        //Update the Amendment Object...
        amendmentObject5.Chamber_History__c = chamberObject5.id;
        update amendmentObject5;
        
        //Now Update the Chamber History to trigger the Test Class...
        chamberObject5.Chamber_History_Status__c = 'Approved by Chamber';
        chamberObject5.Received_From_Chamber_Date__c = System.today();
        update chamberObject5;        
        
        
        //For Amendment Object For Change Company Activity... (ADD)
        Amendment__c amendmentObject6 = new Amendment__c();
        amendmentObject6.RecordTypeId = amendmentRecordTypeMap.get('Company_Amendment_Change_Company_Activity').Id;
        amendmentObject6.Account__c = accountObject.Id;
        amendmentObject6.Action__c = 'Add';
        amendmentObject6.New_Activity_1__c = subActivityObject.id;//Current_Activity_1__c
        amendmentObject6.New_Activity_2__c = subActivityObject1.id;
        //amendmentObject6.New_Activity_3__c = subActivityObject1.id;
        insert amendmentObject6;
        
        
        //For Chamber History Object...
        Chamber_History__c chamberObject6 = new Chamber_History__c();
        chamberObject6.Company__c = accountObject.Id;
        chamberObject6.Chamber_History_Status__c = 'Sent To Chamber';
        chamberObject6.Chamber_Issue_Date__c = System.today();
        chamberObject6.Chamber_Expiry_Date__c = System.today().addYears(1);
        chamberObject6.Sent_to_Chamber_Date__c = System.today();
        chamberObject6.Amendment__c = amendmentObject6.Id;
        chamberObject6.Chamber_of_Commerce_Number__c = '123213';
        insert chamberObject6;
        
        //Update the Amendment Object...
        amendmentObject6.Chamber_History__c = chamberObject6.id;
        
        update amendmentObject6;
        
        //Now Update the Chamber History to trigger the Test Class...
        chamberObject6.Chamber_History_Status__c = 'Approved by Chamber';
        chamberObject6.Received_From_Chamber_Date__c = System.today();
        update chamberObject6;        
        
        
        
        
    }
}